<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script>

  <script src="https://cdn.bootcss.com/vue/2.5.17/vue.js"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.11.0/theme-chalk/index.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.11.0/index.js"></script>
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    <avue-tree :option="option" :data="data" @node-click="nodeClick" @update="update" @save="save" @del="del"
      v-model="form">
      <template slot-scope="scope" slot="menuBtn">
        <el-dropdown-item @click.native="tip(scope.node,scope.data)">自定义按钮</el-dropdown-item>
      </template>
    </avue-tree>

  </div>
</body>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        form: {},
        data: [
          {
            id: 0,
            label: '一级部门',
            value: 0,
            children: [
              {
                id: 1,
                label: '一级部门1',
                value: 0,
              }, {
                id: 2,
                label: '一级部门2',
                value: 0,
              }
            ]
          }, {
            id: 3,
            label: '二级部门',
            value: 0,
            children: [
              {
                id: 4,
                label: '二级部门1',
                value: 0,
              }, {
                id: 5,
                label: '二级部门2',
                value: 0,
              }
            ]
          }
        ],
        option: {
          nodeKey: 'id',
          dialogWidth: '60%',
          formOption: {
            labelWidth: 100,
            column: [{
              label: '自定义项',
              prop: 'test'
            }],
          },
          props: {
            labelText: '标题',
            label: 'label',
            value: 'value',
            children: 'children'
          }
        }
      }
    },
    methods: {
      tip(node, data) {
        this.$message.success(JSON.stringify(data))
      },
      del(data, node, done) {
        this.$message.success('删除回调')
        done();
      },
      update(data, node, done, loadng) {
        this.$message.success('更新回调')
        done();
      },
      save(data, node, done, loadng) {
        this.$message.success('新增回调')
        this.form.id = new Date().getTime();
        this.form.value = new Date().getTime();
        this.form.children = [];
        done();
      },
      nodeClick(data) {
        this.$message.success(JSON.stringify(data))
      }
    }
  })
</script>

</html>